<?php
if(isset($_REQUEST['fuseaction_back'])) {
	$fuseaction_back=$_REQUEST['fuseaction_back'];
}else{
	$fuseaction_back = "";
}  

$v_reason = "";
if(isset($_REQUEST['txt_reason'])){
	$v_reason = _replace_bad_char($_REQUEST['txt_reason']);
} 

$v_record_id_list = "";
if(isset($_REQUEST['hdn_record_id'])){
	$v_record_id_list = $_REQUEST['hdn_record_id'];
}
//echo "abc";exit;
$v_arrs_record_id=explode(",",$v_record_id_list);
//echo "danh sach HS :".$v_record_id; exit;
$v_work = "";
if(isset($_REQUEST['hdn_work'])){
	$v_work = $_REQUEST['hdn_work'];
}
$v_work_date = "";
if(isset($_REQUEST['txt_work_date'])){
	$v_work_date= $_REQUEST['txt_work_date'];
} 
//echo $v_work;exit;
if(_is_sqlserver()){
	$v_worker_id = $_SESSION['staff_id'];
	$sql = " Exec Onegate_RecordWorkSystemUpdate_Vunh " ;
	$sql = $sql . "'" . $v_record_id_list . "'";
	$sql = $sql . "," . $v_worker_id;
	$sql = $sql . ",'" . $v_work . "'";
	$sql = $sql . ",'" . _ddmmyyyy_to_yyyymmdd($v_work_date) . "'" ;
	$sql = $sql . "," . $_ISA_AUTOMATIC_UPDATE_WORK_LIST;
	$sql = $sql . ",'" . $v_reason . "'" ;

	$ado_conn->SetFetchMode(ADODB_FETCH_ASSOC);
	$rs = $ado_conn->GetRow($sql); 
	$v_error = _replace_bad_char(trim($rs['RET_ERROR']));
	//echo "test:=".$sql;exit;
	for($i=0;$i<sizeof($v_arrs_record_id);$i++){
		$v_record_id_i=$v_arrs_record_id[$i];
		
		$sql2="	update 	T_ONEGATE_RECORD  set FK_HANDLE_LEADER_FIRST_TIME=".$v_worker_id; 
	/*if(!in_array($v_work,array('LD_PHONG_TRALAI_THUE','LD_PHONG_TRALAI_PHAT','LD_PHONG_TRALAI_NO_PHAT','LD_PD_KHONG_PHAT'))){
		$sql2=$sql2.",C_APPOINTED_DATE=''";
	}*/
		$sql2=$sql2." where 	pk_record=".$v_record_id_i;

		$ado_conn->SetFetchMode(ADODB_FETCH_ASSOC);
		$rs = $ado_conn->GetRow($sql2); 
		$v_error = _replace_bad_char(trim($rs['RET_ERROR']));
	}

}
sleep(0);
if (!is_null($v_error) && $v_error<>""){?>
	<script>
		alert("<?php echo $v_error; ?>");
		if (_MODAL_DIALOG_MODE==1){
			window.location = "<?php echo $v_goto_url; ?>";
		}else{
			window.history.back();
		}	
	</script><?php
	exit;
}
?>
<form action="index.php" method="post" name="f_back"> 
  <input type="hidden" name="fuseaction" value="<?php echo $fuseaction_back; ?>">
  <input type="hidden" name="fuseaction_back" value="<?php echo $fuseaction_back; ?>">
  <input type="hidden" name="hdn_recordtype_filter" value="<?php echo $v_recordtype_filter; ?>">
</form>

<Script language="javascript">
	document.forms(0).submit();
</Script> 
